package com.asia5b.a5mall.middleware.model.home

import android.text.TextUtils
import com.asia5b.a5mall.middleware.api.NetFectory
import com.asia5b.a5mall.middleware.model.base.BaseModel
import com.asia5b.a5mall.middleware.model.bean.HomeActionIml
import com.asia5b.a5mall.middleware.model.bean.HomeMultiItemEntity
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.JsonUtil
import com.asia5b.a5mall.middleware.utils.dddLog
import com.asia5b.a5mall.middleware.utils.glide.BannerImageInteface
import com.google.gson.reflect.TypeToken

/**
 * Created by zhangyuncai on 2020/1/16.
 */

/*
优惠类型

满折
满减
积分
赠品
赠券
免邮
团购
积分商品
单品立减
第二件半价
秒杀
 */

/**
 * Created by zhangyuncai on 2020/1/16.
 */

class HomeBannerContainerBean(val bannerList: ArrayList<HomeBannerMoel>? = null) : BaseModel(), HomeMultiItemEntity {
    override val itemType: Int
        get() = HomeMultiItemEntity.Banner


}

class HomeBannerMoel : BaseModel(), BannerImageInteface,HomeActionIml {

    var pic_url = ""

    var operation_type = ""

    var operation_param = ""

    override fun showImageUrl(): String {
        return pic_url
    }


}

/*
{
"id": 20,
"pic_url": "https:\/\/javashopa.oss-cn-shenzhen.aliyuncs.com\/jav
"operation_type": "NONE",
"operation_param": null,
"operation_url": null,
"client_type": "WAP",
"country_id": 12
}
 */

class HomeMenuContainerBean(val homeMenuList: ArrayList<HomeMenuModel>? = null) : BaseModel(), HomeMultiItemEntity {
    override val itemType: Int
        get() = HomeMultiItemEntity.Menu
}

class HomeMenuModel : BaseModel(),HomeActionIml {

    var navigation_name = ""

    var image = ""

    var url = ""


}

/*{
"navigation_id": 59,
"navigation_name": "积分商城",
"url": "\/points-mall",
"client_type": "MOBILE",
"image": "http:\/\/javashop-statics.oss-cn-beijing.aliyuncs.com\/v70\/null\/D7FF82F35D024195A90E24AD4783B415.png",
"sort": 17,
"country_id": 12
},*/

class HomeFloorAllModel : BaseModel() {
    var page_data = ""//json格式的字符串


    /**
     * 将上述的json格式的字符串转换为数据模型
     */
    fun getHomeFloorModelList(): ArrayList<HomeFloorItemModel> {
        val homeFloorItemModelList = JsonUtil.jsonToArray(page_data, HomeFloorItemModel::class.java)
        NetFectory.printJson(page_data)
        return homeFloorItemModelList ?: arrayListOf()
    }


}

/*
{
"page_id": 16,
"page_name": "mobile_f
"page_data": "[{\"tpl_
/javashopanormal\/71D8A7DD
id\":0},\"block_opt\":\"\"
"page_type": "INDEX",
"client_type": "WAP",
"country_id": 12
}
 */


class HomeFloorItemModel : BaseModel(), HomeMultiItemEntity, HomeActionIml {

    /**
     * 格局类型
     */
    var tpl_id = 0
    var blockList: ArrayList<HomeBlockModel>? = null

    fun toBannerList(): ArrayList<HomeBlockBannerBean> {
        val list = arrayListOf<HomeBlockBannerBean>()
        blockList?.forEach {
            if (!TextUtils.isEmpty(it.image)) {
                list.add(HomeBlockBannerBean(it.image))
            }
        }
        if (list.size <= 0) {
            list.add(HomeBlockBannerBean(""))
        }
        return list
    }

    override val itemType: Int
        get() = tpl_id
}

class HomeBlockModel : BaseModel(), HomeActionIml {

    //类型 只有 IMAGE/TEXT/GOODS
    var block_type = ""


    //类型不同,值的对象就不同
    var block_value: Any? = null

    //额外参数
    var block_opt: Any? = null

    val optionBean: OptionBean?
        get() {
            if (block_opt != null) {
                return JsonUtil.jsonToObj(JsonUtil.anyToJson(block_opt!!), OptionBean::class.java)
            }
            return null
        }

    var goods: AbsGoodsModel? = null
        get() {
            if (block_type == "GOODS") {
                if (block_value != null && field == null) {
                    val json = JsonUtil.anyToJson(block_value!!)
                    val type = object : TypeToken<AbsGoodsModel>() {}.type
                    dddLog("json:${json}")
                    val homeBlockGoodsBean = JsonUtil.jsonToAny<AbsGoodsModel>(json, type)
                    field = homeBlockGoodsBean
                }
            }
            return field
        }

    var image = ""
        get() {
            return block_value?.toString() ?: ""
        }

    var text = ""
        get() {
            return block_value.toString() ?: ""
        }

}

/**
 * 额外参数
 */
class OptionBean : BaseModel() {
    //标题
    val opt_type: Any? = null

    //描述
    val opt_value: Any? = null

    val optionValueBean: OptionValueBean?
        get() {
            if (opt_value != null) {
                return JsonUtil.jsonToObj(JsonUtil.anyToJson(opt_value!!), OptionValueBean::class.java)
            }
            return null
        }
}

/**
 * 额外参数
 */
class OptionValueBean : BaseModel() {
    //标题
    val title = ""


    //描述
    val desc = ""

}

class HomeBlockBannerBean constructor(var image: String = "") : BaseModel(), BannerImageInteface {

    override fun showImageUrl(): String {
        return image
    }

}

/*
{
"page_id": 16,
"page_name": "mobile_f
"page_data": "[{\"tpl_
/javashopanormal\/71D8A7DD
id\":0},\"block_opt\":\"\"
"page_type": "INDEX",
"client_type": "WAP",
"country_id": 12
}

page_data下的值

[{
"tpl_id": 28,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/B7684811499E4F63B640240A1378155C.gif",
    "block_opt": {
        "opt_type": "URL",
        "opt_value": "http://47.88.223.5:5000/goods?keyword=%E9%A5%AD%E7%9B%92"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/DA1E6B713ABA4E909678AE7CDDDE769F.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "",
    "block_opt": ""
}]
}, {
"tpl_id": 42,
"blockList": [{
    "block_type": "TEXT",
    "block_value": "测试",
    "block_opt": {}
}]
}, {
"tpl_id": 29,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/C0482CD63F42449AA3FDD3AE56988A50.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/8B8F2EA9F3FB42F8941B234248B2C013.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/1CDDE8AA24F94921BE71C22E0E730438.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/59491FB1D1104E74A765655058F56A71.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 42,
"blockList": [{
    "block_type": "TEXT",
    "block_value": "测试2",
    "block_opt": {}
}]
}, {
"tpl_id": 24,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/18312CE7BB654EFDAA3126F39754868B.png",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/8CFA2553D10B477B812BA661B067964E.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/1ADE40D3AF594DA8924F9B1E166A2AD2.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 26,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/FE50011CDF834BF5A834D8BA068CA76B.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/0E8DE5F51F6A450785C2B66937278E0F.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/8450C8ADE3AB4E41AA10892FF285E4A5.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 30,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/87A0B208C59F4BC39C40F7E4003FAC4A.png",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 42,
"blockList": [{
    "block_type": "TEXT",
    "block_value": "测试3",
    "block_opt": {}
}]
}, {
"tpl_id": 25,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/1A1E90C6F6B943F897D8F734F187F31C.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/1FF26F1A2D7B43A7B98269E4F01AFFB2.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/193BF6A691CC4DADA3A01FDDB8352AD9.png",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 29,
"blockList": [{
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/9033EBFFA37048EFA830AAF9C909EC96.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/71D8A7DDF9744364AD8D111AF7E71A21.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/18069D70487D49B5AC31D9071CB43F37.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}, {
    "block_type": "IMAGE",
    "block_value": "https://javashopa.oss-cn-shenzhen.aliyuncs.com/javashopanormal/346DB20CC94E4525A20A23BE300F38A5.jpeg",
    "block_opt": {
        "opt_type": "NONE"
    }
}]
}, {
"tpl_id": 42,
"blockList": [{
    "block_type": "TEXT",
    "block_value": "测试4",
    "block_opt": {}
}]
}, {
"tpl_id": 37,
"blockList": [{
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "木柄硅胶平底锅漏铲煎铲",
        "enable_quantity": -400,
        "thumbnail": "http://47.88.173.86:82/testShopImg/AE7B9E897062423B980DDEAE2238E349_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063160,
        "goods_price": 6.38,
        "goods_id": 8211,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/AE7B9E897062423B980DDEAE2238E349_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 6,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600271",
        "traits_id": 0
    },
    "block_opt": ""
}, {
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "木柄硅胶平底锅油刷",
        "enable_quantity": 0,
        "thumbnail": "http://47.88.173.86:82/testShopImg/B60B319351E048BCA6ABA901242B9C83_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063160,
        "goods_price": 6.38,
        "goods_id": 8210,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/B60B319351E048BCA6ABA901242B9C83_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 6,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600261",
        "traits_id": 0
    },
    "block_opt": ""
}]
}, {
"tpl_id": 37,
"blockList": [{
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "不锈钢厨房捞面勺",
        "enable_quantity": 120,
        "thumbnail": "http://47.88.173.86:82/testShopImg/802FC79B26B44958969C9CF3E41C38EC_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063160,
        "goods_price": 6.49,
        "goods_id": 8205,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/802FC79B26B44958969C9CF3E41C38EC_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 6,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600212",
        "traits_id": 0
    },
    "block_opt": ""
}, {
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "不锈钢平底锅锅铲",
        "enable_quantity": 0,
        "thumbnail": "http://47.88.173.86:82/testShopImg/EC7C80F0501F49E2A825F0EDA289B3EB_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063159,
        "goods_price": 6.49,
        "goods_id": 8204,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/EC7C80F0501F49E2A825F0EDA289B3EB_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 6,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600202",
        "traits_id": 0
    },
    "block_opt": ""
}]
}, {
"tpl_id": 37,
"blockList": [{
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "全硅胶锅铲",
        "enable_quantity": 9959,
        "thumbnail": "http://47.88.173.86:82/testShopImg/A4DA95CF0D27429C97E1EDDB45949DA4_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063159,
        "goods_price": 6.93,
        "goods_id": 8199,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/A4DA95CF0D27429C97E1EDDB45949DA4_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 6,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600156",
        "traits_id": 0
    },
    "block_opt": ""
}, {
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "硅胶手柄平底锅漏铲煎铲",
        "enable_quantity": 0,
        "thumbnail": "http://47.88.173.86:82/testShopImg/A266899034894B2FB909A8B689F2AA99_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574063159,
        "goods_price": 11.55,
        "goods_id": 8198,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/A266899034894B2FB909A8B689F2AA99_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 11,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "157A10",
        "traits_id": 0
    },
    "block_opt": ""
}]
}, {
"tpl_id": 37,
"blockList": [{
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "亚马逊居家必备硅胶手套",
        "enable_quantity": 0,
        "thumbnail": "http://47.88.173.86:82/testShopImg/E4AA42D9A3D3426CA3C2F69AC69BF128_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574062661,
        "goods_price": 8.58,
        "goods_id": 8184,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/E4AA42D9A3D3426CA3C2F69AC69BF128_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 8,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "800403",
        "traits_id": 0
    },
    "block_opt": ""
}, {
    "block_type": "GOODS",
    "block_value": {
        "goods_name": "亚马逊居家必备洗澡刷",
        "enable_quantity": 9999,
        "thumbnail": "http://47.88.173.86:82/testShopImg/B4733F5987D7443084E78238A5972CE1_300x300.jpeg",
        "quantity": 0,
        "create_time": 1574062661,
        "goods_price": 7.15,
        "goods_id": 8185,
        "is_auth": 1,
        "goods_image": "http://47.88.173.86:82/testShopImg/B4733F5987D7443084E78238A5972CE1_300x300.jpeg",
        "seller_name": "全广州最靓的店",
        "price": 7,
        "market_enable": 1,
        "traits_name": "正常",
        "under_message": "",
        "sn": "600408",
        "traits_id": 0
    },
    "block_opt": ""
}]
}]

 */